package com.efounder.form.comp;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.efounder.builder.base.data.DataSetEvent;
import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.form.DMColComponent;
import com.efounder.form.DMComponent;
import com.efounder.form.DataSetComponent;
import com.efounder.form.base.IComponent;
import com.efounder.form.util.FormCompUtil;
import com.efounder.frame.ViewSize;
import com.efounder.imageloader.GlideImageLoader;
import com.efounder.util.AppContext;

/**
 * Created by Javor on 16/9/9.
 */

@SuppressLint("AppCompatCustomView")
public class FormImage_old extends ImageView implements IComponent,IUIComponent,DMComponent,DMColComponent {
    public FormImage_old() {
        super(AppContext.getInstance());
    }

    public FormImage_old(Context context) {
        super(context);
    }

    public FormImage_old(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    private String id;
    private int height;
    private int width;

    private int gap = 0;
    private ViewSize size = new ViewSize(0,0);
    private int percentWidth;
    private int percentHeight;
    private String sourceURL;
//    private ImageLoader imageLoader;
//    private DisplayImageOptions options;


    private EFRowSet mainRowSet;
    private String dataSetColID;
    private String dataSetID;

    private IUIComponent parentComp;


    @Override
    public String getID() {
        return id;
    }

    @Override
    public void setID(String id) {
        this.id = id;
    }

    @Override
    public void creationComplete()
    {
        FormCompUtil.setLayoutSize(this);
    }

    public String getSourceURL() {
        return sourceURL;
    }

    public void setSourceURL(String url) {
        this.sourceURL = url;
//        imageLoader = ImageLoader.getInstance();
//        imageLoader.displayImage(url,this);
        GlideImageLoader.getInstance().displayImage(getContext(),this,url);
    }

    @Override
    public void setLayout() {

    }

    @Override
    public int getGap() {
        return gap;
    }

    @Override
    public void setGap(int gap) {
        this.gap = gap;
    }

    @Override
    public void setCompWidth(int width) {
        this.width = width;
    }

    @Override
    public int getCompWidth(){
        return this.width;
    }

    @Override
    public void setCompHeight(int height) {
        this.height = height;
    }

    @Override
    public int getCompHeight() {
        return this.height;
    }

    @Override
    public int getPercentWidth() {
        return percentWidth;
    }

    @Override
    public void setPercentWidth(int percentW) {
        percentWidth = percentW;
    }

    @Override
    public int getPercentHeight() {
        return percentHeight;
    }

    @Override
    public void setPercentHeight(int percentH) {
        percentHeight = percentH;
    }

    @Override
    public ViewSize getViewSize() {
        return size;
    }

    @Override
    public void setViewSize(ViewSize size) {
        this.size = size;
    }

    @Override
    public String getDataSetColID() {
        return null;
    }

    @Override
    public void setDataSetColID(String dataSetColID) {
        this.dataSetColID = dataSetColID;
    }

    @Override
    public String getDataSetNameColID() {
        return null;
    }

    @Override
    public void setDataSetNameColID(String s) {

    }

    @Override
    public String getInternalDataSetID() {
        return null;
    }

    @Override
    public void setInternalDataSetID(String s) {

    }

    @Override
    public void setViewDataSetID(String s) {

    }

    @Override
    public String getViewDataSetID() {
        return null;
    }

    @Override
    public void setViewDataSetColID(String s) {

    }

    @Override
    public String getViewDataSetColID() {
        return null;
    }

    @Override
    public void setValueDataSetColID(String s) {

    }

    @Override
    public String getValueDataSetColID() {
        return null;
    }

    @Override
    public Boolean getIsUserInternalDataSetID() {
        return null;
    }

    @Override
    public void setIsUserInternalDataSetID(Boolean aBoolean) {

    }

    @Override
    public String getIdentifier() {
        return null;
    }

    @Override
    public Object getPropertyMap() {
        return null;
    }

    @Override
    public void setPropertyMap(Object o) {

    }

    @Override
    public Object getProperty(String s, Object o) {
        return null;
    }

    @Override
    public void setProperty(String s, Object o) {

    }

    @Override
    public int getNumberPrecision() {
        return 0;
    }

    @Override
    public void seNumberPrecision(int i) {

    }

    @Override
    public String getNumberFormat() {
        return null;
    }

    @Override
    public void setNumberFormat(String s) {

    }

    @Override
    public String getColumnType() {
        return null;
    }

    @Override
    public void setColumnType(String s) {

    }

    @Override
    public String getEditorType() {
        return null;
    }

    @Override
    public void setEditorType(String s) {

    }

    @Override
    public String getDateFormat() {
        return null;
    }

    @Override
    public void setDateFormat(String s) {

    }

    @Override
    public String getFormulaOne() {
        return null;
    }

    @Override
    public void setFormulaOne(String s) {

    }

    @Override
    public String getEditMask() {
        return null;
    }

    @Override
    public void setEditMask(String s) {

    }

    @Override
    public String getFkeyID() {
        return null;
    }

    @Override
    public void setFkeyID(String s) {

    }

    @Override
    public String getRlglID() {
        return null;
    }

    @Override
    public void setRlglID(String s) {

    }


    @Override
    public DataSetComponent getDataSetComponent() {
        return null;
    }

    @Override
    public void setDataSetComponent(DataSetComponent dataSetComponent) {

    }

    @Override
    public void setDataSetID(String dataSetID) {
        this.dataSetID = dataSetID;
    }

    @Override
    public String getDataSetID() {
        return null;
    }

    @Override
    public void setDataSet(EFDataSet efDataSet) {

    }

    @Override
    public EFDataSet getDataSet() {
        return null;
    }

    @Override
    public EFRowSet getMainRowSet() {
        return null;
    }

    @Override
    public void dataSetChanged(DataSetEvent dataSetEvent) {
        dataChanged(dataSetEvent.getDataSet());
    }

    public void dataChanged(EFDataSet dataSet) {
        mainRowSet = dataSet.getCurrentRowSet();
        String value = "";
        if (mainRowSet != null){
            value = mainRowSet.getString(dataSetColID, "");
        }
        if ("".equals(value)){
//            setImageResource(R.drawable.default_img);
        }else {
            setSourceURL(value);
        }
    }
    @Override
    public IUIComponent getParentComp() {
        return parentComp;
    }

    @Override
    public void setParentComp(IUIComponent comp) {
        parentComp = comp;
    }
}


